<template>
    
    <section class="main">
        <input type="checkbox" class="toggle-all" />
        <ul class="todo-list">
            <todo-item v-for="item in state.todolist" :key="item.id" :item="item"></todo-item>
        </ul>
    </section>
</template>

<script>
import Constant from "../constants";
import TodoItem from "./TodoItem.vue";

export default {
  name: "TodoList",
  data() {
    return { state: store.state };
  },
  components: {
    TodoItem
  },
  created() {
    //增加新消息事件
    Constant.Event.$on(Constant.ADD_TODO, val => {
      store.addTodo(val);
    });
    //移除消息事件
    Constant.Event.$on(Constant.DESTORY_TODO, id => {
      store.removeTodo(id);
    });
  }
};
</script>
<style lang="scss">
.main {
  position: relative;
  z-index: 2;
  border-top: 1px solid #e6e6e6;
}

label[for="toggle-all"] {
  display: none;
}

.toggle-all {
  position: absolute;
  top: -55px;
  left: -12px;
  width: 60px;
  height: 34px;
  text-align: center;
  border: none; /* Mobile Safari */
}

.toggle-all:before {
  content: "❯";
  font-size: 22px;
  color: #e6e6e6;
  padding: 10px 27px 10px 27px;
}

.toggle-all:checked:before {
  color: #737373;
}

.todo-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.todo-list li {
  position: relative;
  font-size: 24px;
  border-bottom: 1px solid #ededed;
}

.todo-list li:last-child {
  border-bottom: none;
}

@media screen and (-webkit-min-device-pixel-ratio: 0) {
  .toggle-all,
  .todo-list li .toggle {
    background: none;
  }

  .todo-list li .toggle {
    height: 40px;
  }

  .toggle-all {
    -webkit-transform: rotate(90deg);
    transform: rotate(90deg);
  }
}
</style>

